﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SEO.Business;
using SEO.Entity;

public partial class DoSort : AdminPage
{
    /// <summary>
    /// ID
    /// </summary>
    protected int nID;

    /// <summary>
    /// 操作类型
    /// </summary>
    protected string strType = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        strType = Common.GetQueryValue("type", 0);
        int.TryParse(Common.GetQueryValue("id", 0), out nID);

        if (!Page.IsPostBack)
        {
            if (strType == "edit")
            {
                //页面数据初始化
                InitData();
            }
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.Sort;
    }

    /// <summary>
    /// 数据初始化
    /// </summary>
    protected void InitData()
    {
        Sort Info = new BisSort().Get(nID);
        if (Info != null)
        {
            txtName.Text = Info.Name;
            txtLockNumber.Text = Info.LockNumber.ToString();
        }
    }

    /// <summary>
    /// 提交操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Sort Info = new Sort();
        Info.Name = txtName.Text.Trim();
        Info.LockNumber = Convert.ToInt32(txtLockNumber.Text.Trim());
        BisSort bisInfo = new BisSort();
        bool bResult = false;
        if (strType == "edit")
        {
            Info.ID = nID;
            bResult = bisInfo.Update(Info);
        }
        else
        {
            bResult = bisInfo.Insert(Info);
        }
        //结果处理
        if (bResult)
        {
            Until.AlertJS("提交成功！", "ResetPage();");
        }
        else
        {
            Until.Alert("提交失败！");
        }
        RemoveAllSort();
    }
}